﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint.Administration;

namespace Datagility.Shpt.SPDocMirror.Service
{
    class SPMirrorLoggingService: SPDiagnosticsServiceBase
    {     
        public static string DIAG_AREA = "SPDocMirror";     
        private static SPMirrorLoggingService _Current;
     
        public static SPMirrorLoggingService Current     
        {         
            get        
            {             
                if (_Current == null)             
                {                 
                    _Current = new SPMirrorLoggingService();             
                }               
                return _Current;         
            }     
        }       
        
        private SPMirrorLoggingService()
            : base("SPDocMirror Logging Service", SPFarm.Local)     
        {       
        }       
        
        protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()     
        {         
            List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea>{
                new SPDiagnosticsArea(DIAG_AREA, 
                new List<SPDiagnosticsCategory>{
                    new SPDiagnosticsCategory("Error", TraceSeverity.Unexpected, EventSeverity.Error),
                    new SPDiagnosticsCategory("Information", TraceSeverity.Verbose, EventSeverity.Information)
                    })
            };           
            
            return areas;     
        }       
        
        public static void Write(string categoryName, string message)     
        {         
            SPDiagnosticsCategory category = SPMirrorLoggingService.Current.Areas[DIAG_AREA].Categories[categoryName];         
            SPMirrorLoggingService.Current.WriteTrace(0, category, category.TraceSeverity, message);     
        } 
    } 
}
